package com.bite.order.service;

import com.bite.order.api.ProductApi;
import com.bite.order.mapper.OrderMapper;
import com.bite.order.model.OrderInfo;
import com.bite.product.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProductApi productApi;

    public OrderInfo selectById(Integer orderId) {
        OrderInfo orderInfo = orderMapper.selectById(orderId);
//        ProductInfo productInfo = restTemplate.getForObject("http://product-service/product/" + orderInfo.getProductId(), ProductInfo.class);


        ProductInfo productInfo = productApi.selectById(orderInfo.getProductId());
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }
}
